$(function(){

    console.log("开始加载...");
    //初始化js
    if (window.addEventListener) {
        window.addEventListener("load", csh, false);
    } else if (window.attachEvent) {
        window.attachEvent("onload", csh);
    } else {
        window.onload = csh;
    }

});
function csh() {
    //设置语言
    setLanguage();
}


//设置语言
function setLanguage() {

    var languagesMap = {"en_us": "EN_US", "zh_cn": "ZH_CN", "zh_tw": "ZH_TW"};
    var languVal = $.MvcSheetUI.SheetInfo.Language;
    $.MvcSheetUI.SetControlValue("CHANGELANG", languagesMap[languVal]);
    if(!$.MvcSheetUI.GetControlValue("CHANGELANG")){
        $.MvcSheetUI.SetControlValue("CHANGELANG", languagesMap["zh_cn"]);
    }

}

var formerSalesValues="";
function formerSales() {
    var value = $.MvcSheetUI.GetControlValue("REP0_XS");

    if (value == formerSalesValues){
        return;
    }else {
        formerSalesValues=value;
    }

    if (value){
        $.MvcSheetUI.GetElement("formerSales").SheetUser().ClearChoices();
        var param = '{"NAME1":"' + value + '"}';
        $.ajax({
            url: $.MvcSheetUI.PortalRoot + "/RunBizQuery/GetGridData",
            data: {
                "schemaCode": "qeruysalesbyname",
                "queryCode": "querysales",
                "FilterStr": param,
                "PageIndex": 1,
                "PageSize": 20
            },
            dataType: "json",
            async: true,
            success: function (data) {
                var cyzid = null;
                if (data) {
                    if (data.Total && data.Total > 0) {
                        cyzid = data.Rows[0].OBJECTID1;
                    }
                }
                if (!cyzid){
                    cyzid = '18f923a7-5a5e-426d-94ae-a55ad1a4b239';
                }
                $.MvcSheetUI.SetControlValue("formerSales",cyzid);
                console.log($.MvcSheetUI.GetControlValue("formerSales"));
            }
        });

    }

}

